package com.wenfs.demo.service.impl;

import com.wenfs.demo.dao.SysUserMapper;
import com.wenfs.demo.entity.SysUser;
import com.wenfs.demo.service.ISysUser;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @author wefashe
 */
@Service
public class SysUserBo implements ISysUser {
  @Autowired
  private SysUserMapper sysUserMapper;

  @Override
  public void save(SysUser user) {
    Integer maxCode = sysUserMapper.getMaxCode();
    user.setUserCode(String.valueOf(maxCode + 1));
    user.setRegisterTime(String.valueOf(System.currentTimeMillis()));
    user.setUpdateTime(String.valueOf(System.currentTimeMillis()));
    user.setUserId(UUID.randomUUID().toString());
    String salt = UUID.randomUUID().toString();
    user.setPassSalt(salt);
    user.setUserPass(new Md5Hash(user.getUserPass(), user.getPassSalt()).toString());
    user.setUserStatus((byte) 1);
    sysUserMapper.save(user);
  }


  @Override
  public SysUser getUserByUserName(String userName) {
    return sysUserMapper.getUserByUserName(userName);
  }

}
